package svc

import (
	"callsips/internal/config"
	"callsips/internal/model/account/asips"
	"callsips/internal/model/customer/cgateway"
	"callsips/internal/model/customer/risk"
	"callsips/internal/model/sips/cserver"
	"callsips/internal/model/sips/fslog"
	"callsips/internal/model/sips/gateway"
	"callsips/internal/model/sips/srecord"
	"callsips/internal/model/sips/srecorderr"
	"callsips/internal/model/yunhu/accounttaocan"
	"callsips/internal/model/yunhu/mobile"
	"callsips/internal/model/yunhu/mobilebind"
	"github.com/hibiken/asynq"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

type ServiceContext struct {
	Config          config.Config
	AsynqClient     *asynq.Client
	CustomerGateway cgateway.CustomerCgatewayModel
	AccountSips     asips.AccountAsipsModel
	SipGateway      gateway.SipsGatewayModel
	SipCserver      cserver.SipsCserverModel
	SipRecord       srecord.SipsSrecordModel
	SipRecordErr    srecorderr.SipsSrecordErrModel
	SipFsLog        fslog.SipsFslogModel
	CustomerRisk    risk.CustomerRiskModel
	AccountTaocan   accounttaocan.YunhuAccountTaocanModel
	YunhuMobile     mobile.YunhuMobileModel
	YunhuMobileBind mobilebind.YunhuMobileBindModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	sqlConn := sqlx.NewMysql(c.Mysql.Datasource)
	sqlx.DisableLog()
	return &ServiceContext{
		Config:          c,
		AsynqClient:     asynq.NewClient(asynq.RedisClientOpt{Network: "tcp", Addr: c.Cache[0].Host, DB: 2, Password: c.Cache[0].Pass}),
		CustomerGateway: cgateway.NewCustomerCgatewayModel(sqlConn, c.Cache),
		AccountSips:     asips.NewAccountAsipsModel(sqlConn, c.Cache),
		SipGateway:      gateway.NewSipsGatewayModel(sqlConn, c.Cache),
		SipCserver:      cserver.NewSipsCserverModel(sqlConn, c.Cache),
		SipRecord:       srecord.NewSipsSrecordModel(sqlConn, c.Cache),
		SipRecordErr:    srecorderr.NewSipsSrecordErrModel(sqlConn, c.Cache),
		SipFsLog:        fslog.NewSipsFslogModel(sqlConn, c.Cache),
		CustomerRisk:    risk.NewCustomerRiskModel(sqlConn, c.Cache),
		AccountTaocan:   accounttaocan.NewYunhuAccountTaocanModel(sqlConn, c.Cache),
		YunhuMobile:     mobile.NewYunhuMobileModel(sqlConn, c.Cache),
		YunhuMobileBind: mobilebind.NewYunhuMobileBindModel(sqlConn, c.Cache),
	}
}
